﻿using System;
using System.Collections.Generic;
using System.Linq;
using XUCore.Extensions;

namespace XUCore.Timing
{
    public class Quarter
    {
        /// <summary>
        /// 当前年月
        /// </summary>
        public DateTime Date { get; set; }
        /// <summary>
        /// 当前季度
        /// </summary>
        public DateQuarter Current { get; set; }
        /// <summary>
        /// 已经过去的季度（相对的当前日期）
        /// </summary>
        public List<DateQuarter> Befores { get; set; }
        /// <summary>
        /// 还未到的季度（相对的当前日期）
        /// </summary>
        public List<DateQuarter> Afters { get; set; }
        /// <summary>
        /// 所有季度列表
        /// </summary>
        public IList<string> StringQuarters => Befores.Merge(new List<DateQuarter> { Current }).Merge(Afters).Select(c => c.ToString()).ToList();
        /// <summary>
        /// 所有季度列表
        /// </summary>
        public IList<DateQuarter> DateQuarters => Befores.Merge(new List<DateQuarter> { Current }).Merge(Afters).ToList();
    }

    public class DateQuarter
    {
        /// <summary>
        /// 年份
        /// </summary>
        /// <value></value>
        public int Year { get; set; }
        /// <summary>
        /// 季度
        /// </summary>
        public DateQuarterEnum Quarter { get; set; }

        /// <summary>
        /// exp: 2025Q1
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{Year}{Quarter.GetName()}";
        }
    }

    /// <summary>
    /// 日期范围
    /// </summary>
    public enum DateRangeEnum
    {
        /// <summary>
        /// 周
        /// </summary>
        Week,

        /// <summary>
        /// 月
        /// </summary>
        Month,

        /// <summary>
        /// 季度
        /// </summary>
        Quarter,

        /// <summary>
        /// 半年
        /// </summary>
        HalfYear,

        /// <summary>
        /// 年
        /// </summary>
        Year
    }
}